package com.zgr.ssm.controller;

import com.zgr.ssm.entity.ResponseResult;
import com.zgr.ssm.entity.User;
import com.zgr.ssm.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.MethodParameter;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpSession;
import java.lang.reflect.Method;

@Controller
@RequestMapping("/user")
public class UserController {

    @Autowired
    private IUserService userService;

    @RequestMapping(value = "/register.do", method = RequestMethod.POST)
    @ResponseBody
    public ResponseResult<Void> handleRegister(User user){
        userService.addUser(user);
        return new ResponseResult<Void>();
    }

    @RequestMapping(value = "/login.do", method = RequestMethod.POST)
    @ResponseBody
    public ResponseResult<Void> handleLogin(HttpSession session,User user){
        User data = userService.login(user);
        session.setAttribute("uid",data.getId());
        return new ResponseResult<Void>();
    }
}
